package com.ljn.data.web.controller;


import com.ljn.data.entity.AbstractLoginContext;
import com.ljn.data.utils.HostUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public abstract class AbstractController {
    private String refererURL;
    private String remoteIpAddr;
    private HttpSession session;
    private HttpServletRequest request;
    private AbstractLoginContext context;

    public AbstractController() {
    }

    public void init(HttpServletRequest request) {
        this.request = request;
        this.session = request.getSession();
        this.refererURL = request.getHeader("REFERER");
        this.remoteIpAddr = HostUtils.getRemoteIpAddr(request);
        this.context = (AbstractLoginContext)this.session.getAttribute("_LJN_WEBCONTEXT_LOGIN_");
        if (this.context != null) {
            this.context.setLastAccessTime(System.currentTimeMillis());
        }

    }

    public final String getRefererURL() {
        return this.refererURL;
    }

    public final String getRemoteIpAddr() {
        return this.remoteIpAddr;
    }

    public final HttpSession getSession() {
        return this.session;
    }

    public final HttpServletRequest getRequest() {
        return this.request;
    }

    public final AbstractLoginContext getLoginContext() {
        return this.context;
    }

    public final String goback() {
        return this.redirect(this.getRefererURL());
    }

    public final String redirect(String url) {
        return "redirect:" + url;
    }

    public final String getWebAppRealPath() {
        return this.getWebAppRealPath("");
    }

    public final String getWebAppRealPath(String path) {
        return this.session.getServletContext().getRealPath(path);
    }

    public final String getWebAppContextPath() {
        return this.getWebAppContextPath("");
    }

    public final String getWebAppContextPath(String path) {
        return this.request.getContextPath() + path;
    }
}
